import { Asset, JsonAsset } from "cc";
import { tb_container } from "../ExcelConfigDecorator";
import { TbContainer } from "../TbContainer";
import { Tb_Equip } from "./Tb_Equip";

@tb_container(Tb_Equip)
export class Tb_EquipContainer extends TbContainer<Tb_Equip>{

    public decode(data: Asset): void {
        if(data instanceof JsonAsset){//json处理
            let list = data.json as Array<Tb_Equip>
            list.forEach(l=>{
                this.cfgMap.set(l.id,l)
            })
            this.cfgs.concat(list)
            return
        }
        if(data.nativeAsset instanceof ArrayBuffer){//二进制处理
            let buffer = data.nativeAsset
            let view = new DataView(buffer)
            
            let byteLen = buffer.byteLength
            let nowIndex = 0;
            while(nowIndex<byteLen-1){
                //数据类型
                //1.int int[] int[][]
                //2.string string[] string[][]
                //3.bool
                //4.long long[] long[][]
                let cfg:Tb_Equip = new Tb_Equip()
                let id = view.getUint32(nowIndex)
                cfg.id = id;
                nowIndex+=4
                let start = view.getUint32(nowIndex)
                cfg.star = start
                nowIndex+=4
                let level = view.getUint32(nowIndex)
                cfg.level = level
                nowIndex+=4
                this.cfgs.push(cfg)
                this.cfgMap.set(id,cfg)
            }
        }
    }

    public afterDecode(): void {

    }
}

